package com.mchsdk.paysdk.http.process;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;

import org.apache.http.entity.StringEntity;

import com.lidroid.xutils.http.RequestParams;
import com.mchsdk.paysdk.bean.ChannelAndGameInfo;
import com.mchsdk.paysdk.bean.PersonalCenterModel;
import com.mchsdk.paysdk.config.MCHConstant;
import com.mchsdk.paysdk.http.request.UserInfoRequest;
import com.mchsdk.paysdk.utils.MCLog;
import com.mchsdk.paysdk.utils.RequestParamUtil;

import android.os.Handler;

public class UserInfoProcess {

	private static final String TAG = "UserInfoProcess";

	private String account;
	private String type;

	private String getParamStr() {
		Map<String, String> map = new HashMap<String, String>();
		if ("0".equals(type)) {// 正常登陆
			map.put("user_id", PersonalCenterModel.getInstance().getUserId());
		}else if("1".equals(type)){
			map.put("user_id", account);
		}
		map.put("account", PersonalCenterModel.getInstance().getAccount());
		map.put("game_id", ChannelAndGameInfo.getInstance().getGameId());
		map.put("type", type);
		// map.put("game_name", MCHConstant.getInstance().getGameName());
		// map.put("game_appid", MCHConstant.getInstance().getGameAppid());
		// map.put("promote_id", MCHConstant.getInstance().getPromoteId());
		// map.put("promote_account",
		// MCHConstant.getInstance().getPromoteAccount());
		MCLog.w(TAG, "fun#ptb_pay params:" + map.toString());
		return RequestParamUtil.getRequestParamString(map);
	}

	public void post(Handler handler) {
		RequestParams params = new RequestParams();
		try {
			params.setBodyEntity(new StringEntity(getParamStr().toString()));
		} catch (UnsupportedEncodingException e) {
			params = null;
			MCLog.e(TAG, "fun#ptb_pay UnsupportedEncodingException:" + e);
		}
		if (null != handler) {
			new UserInfoRequest(handler).post(MCHConstant.getInstance().getUserInfoUrl(), params);
		    MCLog.w(TAG, MCHConstant.getInstance().getUserInfoUrl());
		}else{
			MCLog.e(TAG, "fun#post handler is null or url is null");
		}
	}

	public void setAccount(String account) {
		this.account = account;
	}

	public void setType(String type) {
		this.type = type;
	}
}
